package com.delio.client.login;

import java.util.List;

import com.delio.client.Delio;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RootPanel;

public class Usuarios {
  static UsuarioForm uf;
	//private static UsuarioServiceAsync us = GWT.create(UsuarioService.class);
    private static UsServiceAsync usa = GWT.create(UsService.class);
	
	public static void validar(Usuario u){
		
		usa.validar(u, new AsyncCallback<Boolean>(){

			@Override
			public void onFailure(Throwable caught) {
			   MessageBox.alert("Error","Error al logearse" , null);	
			}

			@Override
			public void onSuccess(Boolean result) {
     		    if(result){
     		       	
     		    	
     		       uf.hide(); 
     		       Delio dl = new Delio();
     		       Viewport v = new Viewport();
     		       v.setLayout(new FitLayout());  
     		       v.add(dl);
 		   	       RootPanel.get().add(v);
     		    }else{	
     		      MessageBox.alert("Error","No es usuario del Sistema" , null);	
     		    }
			}
			
		});
	}
	
	public static void ListarUs(){
		
		usa.ListarUs(new AsyncCallback<List<Usuario>>(){

			@Override
			public void onFailure(Throwable caught) {
				MessageBox.alert("ERROR", "ERRORRRRR", null);
				
			}

			@Override
			public void onSuccess(List<Usuario> result) {
				MessageBox.alert("Bien", "Biennnnnnn", null);
				
			}
		
		});
	}
}
